package main

import "fmt"

type Person1 struct {
	// 匿名字段 普通情况下不推荐
	// 结构体内如果是匿名字段，则字段名称必须唯一，
	string
	int
}

type Person struct {
	Name  string
	Age   int
	Hobby []string
	map1  map[string]string
}

type User struct {
	Username string
	Password string
	Address  Address // 表示User结构体嵌套了Address结构体 若后面不加类型就是匿名结构体
	// 如果结构体中成员命名有和嵌套结构体成员重名，优先访问最外层的成员
	// 结构体嵌套也叫继承 比如在其他结构体方法中就可以使用嵌套结构体的成员
}

type Address struct {
	Name  string
	Phone string
	City  string
}

func main() {
	// p := Person1{"Tom", 25}

	var p Person
	p.Name = "Tom"
	p.Age = 25
	p.Hobby = make([]string, 3, 6)
	p.Hobby[0] = "读书"
	p.Hobby[1] = "玩游戏"
	p.Hobby[2] = "打篮球"
	// p.Hobby = []string{"读书", "玩游戏"}
	// p.map1 = map[string]string{"key1": "value1", "key2": "value2"}
	p.map1 = make(map[string]string)
	p.map1["address"] = "北京"
	p.map1["phone"] = "1234567890"

	fmt.Println(p)
	fmt.Printf("%#v\n", p)

	fmt.Println("~~~~~~~~~~~~~~~~~~~~")

	var u User

	u.Username = "admin"
	u.Password = "123456"
	u.Address.Name = "瑟琳"
	u.Address.Phone = "1234567890"
	u.Address.City = "狄斯"

	fmt.Printf("%#v\n", u)
	u.Address.Name = "毕安卡"
	fmt.Printf("%#v\n", u)

}
